package io.renren.modules.project.service.impl;

import io.renren.common.utils.RandomId;
import io.renren.modules.project.dao.ProjectEntityDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.modules.project.dao.PrjectMessageDao;
import io.renren.modules.project.entity.PrjectMessageEntity;
import io.renren.modules.project.service.PrjectMessageService;



@Service("prjectMessageService")
public class PrjectMessageServiceImpl implements PrjectMessageService {
	@Autowired
	private PrjectMessageDao prjectMessageDao;
	@Autowired
	private ProjectEntityDao projectEntityDao;
	
	@Override
	public PrjectMessageEntity queryObject(String id){
		return prjectMessageDao.queryObject(id);
	}
	
	@Override
	public List<PrjectMessageEntity> queryList(Map<String, Object> map){
		return prjectMessageDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return prjectMessageDao.queryTotal(map);
	}
	
	@Override
	public void save(PrjectMessageEntity prjectMessage){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date();
		prjectMessage.setId(RandomId.createId()+"");
		prjectMessage.setSentData(sdf.format(date));
		prjectMessageDao.save(prjectMessage);
		//return prjectMessage;
	}


	
	@Override
	public void update(PrjectMessageEntity prjectMessage){
		prjectMessageDao.update(prjectMessage);
	}
	
	@Override
	public void delete(String id){
		prjectMessageDao.delete(id);
	}
	
	@Override
	public void deleteBatch(String[] ids){
		prjectMessageDao.deleteBatch(ids);
	}

	@Override
	public List<PrjectMessageEntity> queryProjectId(String projectId) {
		List<PrjectMessageEntity> prjectMessageList = prjectMessageDao.queryProjectId(projectId);
		return prjectMessageList;
	}

	@Override
	public List<PrjectMessageEntity> queryUserMessage(String userId) {
		List<PrjectMessageEntity> prjectMessageEntityList = null;
				//查出用户所负责任务的项目ID
		List<String> projectList = projectEntityDao.userQueryTask(userId);
		//查出用户所负责的项目
		List<String> idList = projectEntityDao.queryManagerOnlyList(userId);
		projectList.addAll(idList);
		if (projectList != null && projectList.size()>0){
			String[] strings = new String[projectList.size()];
			prjectMessageEntityList = prjectMessageDao.queryUserMessage(projectList.toArray(strings));
		}
		return prjectMessageEntityList;
	}
}
